import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  Put,
} from '@nestjs/common';
import { DictDataService } from './dicts-data.service';
import { CreateDictDataDto } from './dto/create-dict-data.dto';
import { UpdateDictDatumDto } from './dto/update-dict-data.dto';
import { SearchDto } from '@/common/dto/base-search.dto';
import { ApiOperation } from '@nestjs/swagger';
import { IdsDto } from '@/common/dto/ids.dto';

@Controller('dicts/:dictCode/items')
export class DictDataController {
  constructor(private readonly dictDataService: DictDataService) {}

  @Post()
  @ApiOperation({ summary: '新增字典数据' })
  create(
    @Param('dictCode') dictCode: string,
    @Body() CreateDictDataDto: CreateDictDataDto,
  ) {
    return this.dictDataService.create(dictCode, CreateDictDataDto);
  }

  @Get('page')
  @ApiOperation({ summary: '分页查询字典数据' })
  findAll(@Param('dictCode') dictCode: string, @Query() query: SearchDto) {
    return this.dictDataService.findAll(dictCode, query);
  }

  @Get()
  @ApiOperation({ summary: '字典项列表' })
  findList(@Param('dictCode') dictCode: string) {
    return this.dictDataService.findList(dictCode);
  }

  @Get(':id/form')
  @ApiOperation({ summary: '查询字典数据详情' })
  findOne(@Param() params: { dictCode: string; id: string }) {
    return this.dictDataService.findOne(params);
  }

  @Put(':id')
  @ApiOperation({ summary: '修改字典数据' })
  update(
    @Param() params: { dictCode: string; id: string },
    @Body() updateDictDatumDto: UpdateDictDatumDto,
  ) {
    return this.dictDataService.update(params, updateDictDatumDto);
  }

  @Delete(':ids')
  @ApiOperation({ summary: '删除字典数据' })
  remove(@Param() params: IdsDto) {
    return this.dictDataService.remove(params);
  }
}
